﻿//display grid common actions 
    function submitform()
    {
        document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = 1;
        document.aspnetForm.submit();
    }
    function moveGridPage(page_id)
    {
        if (eval(page_id) <= 0) //if (page_id <= 0) // changed by Jeya Prabha 
        {
            return false;
        }

        //alert(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value);
        //alert(document.getElementById("ctl00_ContentPlaceHolder3_hihLastPageId").value);
        
        var last_page_id=document.getElementById("ctl00_ContentPlaceHolder3_hihLastPageId").value;//var last_page_id=document.getElementById("hihLastPageId").value;
        
        if (eval(page_id) > eval(last_page_id))//if (page_id > last_page_id) // changed by Jeya Prabha 
        {
            return false;
        }
        document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = page_id;//document.getElementById("hihCurrentPageId").value = page_id;
        return true;
    }
    function GetEditPageURL() // Added by srivatsan to get Edit page URL
    {
        var URLstring = "";
        if(document.getElementById("ctl00_ContentPlaceHolder3_hiheditpageURL")!=null)
        {
            URLstring = document.getElementById("ctl00_ContentPlaceHolder3_hiheditpageURL").value;
        }
       // alert(URLstring);
        return URLstring;
    }
    function SetFirstPage()
    {
        resetObjectSearch(false);
        if(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId")!=null)
        {
            //alert(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value);
            document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = "1";
        }
        mb_processFilterGo();
        return false;
    }
    function FilterClick()
    {
    //alert("inside filter click");
        resetObjectSearch(false);        
        if(document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick")!=null)
        {
            //alert("controlfound");
            //if(document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick").value=="0" || document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick").value =="")
           // {
                document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick").value = "1";
            //}
           // else
           // {
             //   document.getElementById("ctl00_ContentPlaceHolder3_hffilterclick").value = "0";
           // }
        }
        
    }
    function DeleteClick(strDelPK,intCurrentPage)
    {
       
    if(document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteafrowid")!=null)
    {
    
        document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteafrowid").value = strDelPK;
        //alert(strDelPK);
    }
    if(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId")!=null)
    {
    
        document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = intCurrentPage;
        //alert(intCurrentPage);
    }
     if(document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteClick")!=null)
     {
        //alert("delete clicked");
        document.getElementById("ctl00_ContentPlaceHolder3_hihDeleteClick").value = "1";
     }
    }
    function interceptObjectSearch(ee)
    {
        try
        {
//            if (document.layers)
//                Key = ee.which;
//            else
//                Key = window.event.keyCode;            
//            if (Key == 13)
            var code = (ee.keyCode ? ee.keyCode : ee.which); // Added by 'Imran Gani' on 10-Dec-2013, to get enter key value from event
            if (code == 13)
            {  
                //alert("Key pressed! ASCII-value: " + Key);
                var ret = doObjectSearch();
                if (ret == true) __doPostBack('','');
                return false;
            }     
        }
        catch(Exintercept){}
    }
    function doObjectSearch()
    {
        try
        {
            if (document.getElementById("ctl00_ContentPlaceHolder3_txtObjectSearch")!=null)
            {
                var strObjectSearch = document.getElementById("ctl00_ContentPlaceHolder3_txtObjectSearch").value;
                if (strObjectSearch.length<1)
                {
                    alert("Please enter a search string to continue.");
                    return false;
                }
                else if (strObjectSearch == "Record Search")
                {
                    alert("Please enter a search string to continue.");
                    return false;
                }
             }
             if(document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId")!=null)
            {
                document.getElementById("ctl00_ContentPlaceHolder3_hihCurrentPageId").value = "1";
            }
            if (document.getElementById("ctl00_ContentPlaceHolder3_hfObjectSearch")!=null)
            {
                document.getElementById("ctl00_ContentPlaceHolder3_hfObjectSearch").value = "search";                
            }
        }
        catch(ExSearch){}
        return true;
    }
    function resetObjectSearch(resetSearchText)//was used in "View all" link, to be removed if no other issues arise from view all
    {
        try
        {
            if (document.getElementById("ctl00_ContentPlaceHolder3_hfObjectSearch")!=null)
                document.getElementById("ctl00_ContentPlaceHolder3_hfObjectSearch").value = "";
            if (resetSearchText==true)
            {
                if (document.getElementById("ctl00_ContentPlaceHolder3_txtObjectSearch")!=null)
                    document.getElementById("ctl00_ContentPlaceHolder3_txtObjectSearch").value = "";
            }
        }     
        catch(ExResetSearch){}
    }
    function mb_datasrch_txt_focus(th)
    {
        try
        {
            document.getElementById('ctl00_ContentPlaceHolder3_ImageButton1').src = "Images/objectSearch2.gif";
            if (th.value == "Record Search")
            {
                th.value = "";   
            }
            mb_datasrch_changetxtStyle();
            th.select();
        }
        catch(Ex_mb_datasrch){}
    }
    function mb_datasrch_txt_blur(th)
    {
        try
        {
            document.getElementById('ctl00_ContentPlaceHolder3_ImageButton1').src = "Images/objectSearch2_disabled.gif";
            if (th.value == "")
                th.value = "Record Search";
            mb_datasrch_changetxtStyle();
        }
        catch(Ex_mb_datasrch){}
    }
    function mb_datasrch_changetxtStyle()
    {
        document.getElementById('ctl00_ContentPlaceHolder3_txtObjectSearch').style.color = document.getElementById('ctl00_ContentPlaceHolder3_txtObjectSearch').value=='Record Search' ? '#808080' : '#000000';
    }
    function mb_datasrch_img_focus()
    {
        document.getElementById('ctl00_ContentPlaceHolder3_ImageButton1').src = "Images/objectSearch2.gif";
    }  
    function mb_datasrch_img_blur()
    {
        document.getElementById('ctl00_ContentPlaceHolder3_ImageButton1').src = "Images/objectSearch2_disabled.gif";
    }  
function mb_processFilterGo()
{
    var filterNode = document.getElementById("table51");
    if (filterNode == null)
        return false;
    //var anchorNodes = fromParentNode.getElementsByTagName("a");
    var mb_loca = document.location.href;
    var curVariables = mb_getCurUrlVariables();
    var newVariables = [], hash;
    var inputNodes = filterNode.getElementsByTagName("select");
    //add filter flag
    newVariables.push('flmode');
    newVariables['flmode'] = '1';
    var isActuallyFilterORReset = false;//identify users selects --all-- for all.
    for (var i = 0; i < inputNodes.length; i++) {
            newVariables.push(inputNodes[i].id.replace('ctl00_ContentPlaceHolder3_Quick_Search_',''));
            newVariables[inputNodes[i].id.replace('ctl00_ContentPlaceHolder3_Quick_Search_','')] = escape(inputNodes[i].value);
            isActuallyFilterORReset = isActuallyFilterORReset == true ? true : (isActuallyFilterORReset == (inputNodes[i].value == '--All--'));
    }  
    if (isActuallyFilterORReset==false)//users tried to reset filter
    {
        mb_loadViewAllUrl();
        return false;
    }
    // added by 'Imran Gani' on 27-Jun-2013, to append a parameter for page view type in URL
    newVariables.push('pgtype');
    newVariables['pgtype'] = $('#ctl00_ContentPlaceHolder3_ddlPageViewType').val();
    //remove old variables when new exists
    var mb_go_url = window.location.href.substr(0,window.location.href.indexOf('?'));
    for (var i = 0; i < newVariables.length; i++) {        
        if (curVariables[newVariables[i]] == undefined)//not exists
        {
            curVariables.push(newVariables[i]);
            curVariables[newVariables[i]] = newVariables[newVariables[i]];
        }
        else //exists
        {
            curVariables[newVariables[i]] = newVariables[newVariables[i]]; //fix this later
        }
    }
    //
    for (var i = 0; i < curVariables.length; i++) {        
        mb_go_url += (i==0 ? '?' : '&') + curVariables[i] + "=" + curVariables[curVariables[i]];
    }
    document.location.href = mb_go_url;
}
function mb_getCurUrlVariables()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = escape(hash[1]);        
    }
    return vars;
}
function mb_loadViewAllUrl()
{
    try
    {
        var vieAllNodes = document.getElementById('ctl00_ltaccordian').getElementsByTagName("a");
        var loadUrl = vieAllNodes[vieAllNodes.length-1].getAttribute('href');
        if (loadUrl.length>0)
            window.location.href = loadUrl;
    }
    catch(ex_mb_vieall)
    {
        alert("Unable to load the page. Please use the menu to navigate");
    }
}
function mb_updateGoButton()
{
    try
    {
        document.getElementById('ctl00_ContentPlaceHolder3_btngo').value = ' Go ';
        var filterNode = document.getElementById("table51");
        if (filterNode == null)
            return false;
        var inputNodes = filterNode.getElementsByTagName("select");
        var isActuallyFilterORReset = false;//identify users selects --all-- for all.
        for (var i = 0; i < inputNodes.length; i++) {
            isActuallyFilterORReset = isActuallyFilterORReset == true ? true : (isActuallyFilterORReset == (inputNodes[i].value == '--All--'));
            if (isActuallyFilterORReset == true) break;            
        }  
        if (isActuallyFilterORReset==false)//users tried to reset filter
        {
            document.getElementById('ctl00_ContentPlaceHolder3_btngo').value = 'View All';
        }
    }
    catch(ex_mb_updtgo)
    {
        
    }
}
function mb_disableFilterInvokeButton()
{
    try
    {
        if (document.getElementById('ctl00_ContentPlaceHolder3_btngo')!=null && document.getElementById('table51')!=null)//filter mode
        {
            document.getElementById('mb_filter_img').style.display='none';
        }        
    }
    catch(ex_mb_disbflbtn)    {}
}